package com.groupbuying.admin.controller;

import com.groupbuying.admin.domain.UserDO;
import com.groupbuying.admin.dto.UserDTO;
import com.groupbuying.admin.dto.do2dto.UserConvert;
import com.groupbuying.admin.service.RoleService;
import com.groupbuying.admin.service.UserService;
import com.groupbuying.admin.context.FilterContextHandler;
import com.groupbuying.admin.dto.LoginUserDTO;
import com.groupbuying.admin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * O2O模块控制器
 * @author groupbuying
 */
@RequestMapping("/store")
@RestController
public class O2OController extends BaseController {
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
	/**
	 * 登录的当前用户，前台需要验证用户登录的页面可以调用此方法
	 * @return
	 */
    @GetMapping("/currentUser")
	LoginUserDTO currentUser(){
		LoginUserDTO loginUserDTO = new LoginUserDTO();
		loginUserDTO.setUserId(FilterContextHandler.getUserID());
		loginUserDTO.setUsername(FilterContextHandler.getUsername());
		loginUserDTO.setName(FilterContextHandler.getName());
		return loginUserDTO;
	}

	/**
	 * 根据用户id获取用户
	 * @param id
	 * @return
	 */
    @GetMapping("{id}")
	R get(@PathVariable("id") Long id ){
		UserDTO userDTO = UserConvert.MAPPER.do2dto(userService.get(id));
    	return R.ok().put("data",userDTO);
	}

	/**
	 * 增加服务商
	 * @param user
	 * @return
	 */
	@PostMapping()
	R save(@RequestBody UserDO user) {
		//user.setPassword(MD5Utils.encrypt(user.getUsername(), user.getPassword()));
		//return R.operate(userService.save(user) > 0);
		return null;
	}


}
